﻿using System;
using System.Linq;
using GdHotel.Data.Interfaces;

namespace GdHotel.Data.Repositories
{
    public class SideBlocksCustomPagesRepository : ISideBlocksCustomPagesRepository
    {
        private GdHotelEntities entities = new GdHotelEntities();

        public IQueryable<SideBlockCustomPage> FindAll()
        {
            return entities.SideBlockCustomPages.AsQueryable();
        }

        public IQueryable<SideBlockCustomPage> FindAllByLang(Language lang)
        {
            return entities.SideBlockCustomPages.Where(item => item.LanguageId == lang.Id).AsQueryable();
        }

        public SideBlockCustomPage GetById(Int32 id)
        {
            return entities.SideBlockCustomPages.SingleOrDefault(item => item.Id == id);
        }

        public void Insert(SideBlockCustomPage item)
        {
            entities.AddToSideBlockCustomPages(item);
        }

        public void Delete(SideBlockCustomPage item)
        {
            entities.SideBlockCustomPages.DeleteObject(item);
        }

        public void Save()
        {
            entities.SaveChanges();
        }

        public void Dispose()
        {
            entities.Dispose();
        }
    }
}
